package com.example.test_witns.ui.user_page;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.test_witns.R;
import com.example.test_witns.databinding.ActivityUserPageBinding;
import com.example.test_witns.ui.add_friend_requset.ActivityAddFriendRequest;

import de.hdodenhof.circleimageview.CircleImageView;

public class UserPageActivity extends AppCompatActivity {

    ActivityUserPageBinding binding;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityUserPageBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        Intent intent = getIntent();
        String userEmail = intent.getStringExtra("userEmail");
        String nickname = intent.getStringExtra("nickname");
        String uuid = intent.getStringExtra("uuid");
        byte[] userAvatarBytes = intent.getByteArrayExtra("userAvatarBytes");

        CircleImageView userAvatar = findViewById(R.id.userAvatar);
        if (userAvatarBytes != null) {
            userAvatar.setImageBitmap(BitmapFactory.decodeByteArray(userAvatarBytes, 0, userAvatarBytes.length));
        }

        if (getIntent() != null){
            TextView user_introduction_uuid = findViewById(R.id.user_introduction_uuid);
            TextView user_introduction_username = findViewById(R.id.user_introduction_username);
            user_introduction_uuid.setText(userEmail);
            user_introduction_username.setText(nickname);
        }

        View user_introduction_back = findViewById(R.id.navigation_user_introduction_back);
        user_introduction_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        View send_add_friend_request = findViewById(R.id.send_add_friend_request);
        send_add_friend_request.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), ActivityAddFriendRequest.class);
                intent.putExtra("nickname", nickname);
                intent.putExtra("uuid",uuid);
                intent.putExtra("userEmail", userEmail);
                intent.putExtra("userAvatarBytes", userAvatarBytes);
                startActivity(intent);
            }
        });

    }

}